package com.yl.demo.service.impl;

import com.yl.demo.mapper.SysPermissionMapper;
import com.yl.demo.mapper.SysRoleMapper;
import com.yl.demo.mapper.UserMapper;
import com.yl.demo.model.SysPermission;
import com.yl.demo.model.SysRole;
import com.yl.demo.model.UserInfo;
import com.yl.demo.service.UserService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: 用户信息实现类
 * @Author: YL
 * @CreateDate: 2018/10/24 14:15
 * @Version: 1.0
 */
@Service("userService")
public class UserServiceImpl implements UserService {

    @Resource
    UserMapper userMapper;

    @Resource
    SysRoleMapper roleMapper;

    @Resource
    SysPermissionMapper permissionMapper;

    /**
     * @Description: 根据用户名称查询用户信息
     * @Author: YL
     * @CreateDate: 2018/10/24 14:23
     * @Version: 1.0
     */
    @Override
    @Cacheable("queryUserByName")
    public UserInfo queryUserByName(String userName) {
        UserInfo userInfo = userMapper.findUserByName(userName);
        return userInfo;
    }

    /**
     * @return
     * @Description: 根据用户名称查询用户角色信息
     * @author YL
     * @date 2018/10/24 15:01
     */
    @Override
    public List<SysRole> queryRoleList(String userName) {
        List<SysRole> sysRoles = roleMapper.queryRoleList(userName);
        return sysRoles;
    }

    /**
     * @return
     * @Description: 根据用户名称查询用户权限信息
     * @author YL
     * @date 2018/10/24 15:01
     */
    @Override
    public List<SysPermission> queryPermissionList(String userName) {
        List<SysPermission> permissionList = permissionMapper.queryPermissionList(userName);
        return permissionList;
    }


}
